package org.korifey.ffbdd.chess;

import java.util.Iterator;
import java.util.List;

public class ChessBasic {
	
	public String solve(Position pos, int nturnes) {
		return inner(pos, nturnes);
	}
	
	public String inner(Position pos, int turnesLeft) {
		if (pos.whiteMove) {
			if (turnesLeft == 0) return null;
			List<Position> nextpos = pos.nextPossiblePositions();
			for (Position p: nextpos) {
				if (inner(p, turnesLeft) != null) return null;//p.getLastMove(); 
			}
			return null;
			
		} else {
			if (pos.isCheckmate()) return "";
			List<Position> nextpos = pos.nextPossiblePositions();
			if (nextpos.size() == 0) {
				//stalemate
				return null;
			}
			for (Position p: nextpos) {
				if (inner(p, turnesLeft-1) == null) return null; 
			}
			return "";
		}
	}
}
